package com.ruoyi.web.controller.decision;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.decision.domain.Scheme;
import com.ruoyi.decision.domain.Task;
import com.ruoyi.decision.service.ISchemeService;
import com.ruoyi.decision.service.ITaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 决策方案Controller
 * 
 * @author zbw
 * @date 2022-07-20
 */
@RestController
@RequestMapping("/decision/scheme")
public class SchemeController extends BaseController
{
    @Autowired
    private ISchemeService schemeService;

    @Autowired
    private ITaskService taskService;



//    /**
//     * 新增  决策方案 与 方案，策略中间表
//     */
//    @PreAuthorize("@ss.hasPermi('decision:scheme:addschemestrategy')")
//    @Log(title = "决策方案", businessType = BusinessType.INSERT)
//    @PostMapping("addschemestrategy")
//    public AjaxResult addschemestrategy(@RequestBody Scheme scheme)
//    {
//        try {
//            String s = schemeService.insertSchemestrategy(scheme);
//            return toAjax(0);
//        } catch (Exception e) {
//            e.printStackTrace();
//            return toAjax(1);
//        }
//    }

    /**
     * 方案审核
     */
    @PreAuthorize("@ss.hasPermi('decision:scheme:examine')")
    @PutMapping("/examine/{schemeId}")
    public AjaxResult examine(@PathVariable("schemeId") String schemeId)
    {
        return toAjax(schemeService.updateSchemeByExamine(schemeId));
    }

    /**
     * 方案上报
     */
    @PreAuthorize("@ss.hasPermi('decision:scheme:report')")
    @PutMapping("/report/{schemeId}")
    public AjaxResult report(@PathVariable("schemeId") String schemeId)
    {
        return toAjax(schemeService.updateSchemeByReport(schemeId));
    }

    /**
     * 查询决策方案列表
     */
    @PreAuthorize("@ss.hasPermi('decision:scheme:list')")
    @GetMapping("/list")
    public TableDataInfo list(Scheme scheme)
    {
        startPage();
        List<Scheme> list = schemeService.selectSchemeList(scheme);
        return getDataTable(list);
    }

    /**
     * 导出决策方案列表
     */
    @PreAuthorize("@ss.hasPermi('decision:scheme:export')")
    @Log(title = "决策方案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Scheme scheme)
    {
        List<Scheme> list = schemeService.selectSchemeList(scheme);
        ExcelUtil<Scheme> util = new ExcelUtil<Scheme>(Scheme.class);
        util.exportExcel(response, list, "决策方案数据");
    }

    /**
     * 获取决策方案详细信息
     */
    @PreAuthorize("@ss.hasPermi('decision:scheme:query')")
    @GetMapping(value = "/{schemeId}")
    public AjaxResult getInfo(@PathVariable("schemeId") String schemeId)
    {
        return AjaxResult.success(schemeService.selectSchemeBySchemeId(schemeId));
    }

    /**
     * 新增决策方案
     */
    @PreAuthorize("@ss.hasPermi('decision:scheme:add')")
    @Log(title = "决策方案", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Scheme scheme)
    {
        return toAjax(schemeService.insertScheme(scheme));
    }

    /**
     * 修改决策方案
     */
    @PreAuthorize("@ss.hasPermi('decision:scheme:edit')")
    @Log(title = "决策方案", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Scheme scheme)
    {
        return toAjax(schemeService.updateScheme(scheme));
    }

    /**
     * 删除决策方案
     */
    @PreAuthorize("@ss.hasPermi('decision:scheme:remove')")
    @Log(title = "决策方案", businessType = BusinessType.DELETE)
	@DeleteMapping("/{schemeIds}")
    public AjaxResult remove(@PathVariable String[] schemeIds)
    {
        return toAjax(schemeService.deleteSchemeBySchemeIds(schemeIds));
    }
}
